package com.qf.dao.impl;

import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.utils.DBUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author 29125
 * @version V1.0
 * @Project java2203
 * @Package com.qf.dao.impl
 * @Description:
 * @Date 2022/5/27 13:38
 */
public class UserDaoImpl implements UserDao {
    //用户登录
    //dbutils工具类
    private QueryRunner queryRunner=new QueryRunner(DBUtil.getDataSource());

    @Override
    public User findByUserName(String username) {
        String sql=" select * from user where username=? ";
        try {
            User user=queryRunner.query(sql,new BeanHandler<User>(User.class),username);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public User select(String username, String password) {

        String sql = " select * from user where username=? and password=? ";
        try {
            User user=queryRunner.query(sql, new BeanHandler<User>(User.class)  ,username,password);
            return user;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
